#!/usr/bin/python
# -*- coding: UTF-8 -*-
# ========================
# @Time  : 2020/3/10 11:55
# @Author: Mecell
# @File  : yaml_packaging.py
# ========================

import yaml



class YamlHandle:
    """
    定义一个读写yaml文件的类
    """
    def __init__(self, filename):
        self.filename = filename
        with open(self.filename, "r", encoding="utf-8") as self.file:
            self.source = self.file.read()


    def get_data(self, key):
        """
        获取读取yaml文件数据
        :param key:
        :return: 嵌套字典的列表
        """
        self.yaml_data = yaml.load(self.source, Loader=yaml.FullLoader)
        return self.yaml_data[key]


if __name__ == '__main__':
    from common.path_constants import COMPANY_TRAINING_YAML
    yaml_obj = YamlHandle(COMPANY_TRAINING_YAML)
    yaml_data = yaml_obj.get_data('upload_file')
    print(type(yaml_data),yaml_data)
    for i in range(len(yaml_data)):
        print(type(yaml_data[i]),yaml_data[i])
    # print(type(yaml_data[0]["data"]), yaml_data[0]["expected_res"]["data"]["newUser"])
    # print("\'date'字段值eval转换前：",yaml_data[0]['date'])
    # print("\'date'字段值eval转换前：",eval(yaml_data[0]['date']))
